package com.ruoyi.web.controller.fund;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.balanceReturn.domain.HouseReturnT;
import com.ruoyi.balanceReturn.service.IHouseReturnTService;
import com.ruoyi.costQuery.domain.HouseCostT;
import com.ruoyi.data.MD5;
import com.ruoyi.refund.domain.HouseRefundT;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.door.domain.HouseDoorT;
import com.ruoyi.door.service.IHouseDoorTService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 户管理Controller
 * 
 * @author lijie
 * @date 2023-05-04
 */
@RestController
@RequestMapping("/fund/return")
public class HouseReturnTController extends BaseController
{
    @Autowired
    private IHouseDoorTService houseDoorTService;
    @Autowired
    private IHouseReturnTService houseReturnTService;

    /**
     * 查询户管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseDoorT houseDoorT) throws Exception {
        startPage();
        if(houseDoorT.getUserName()!=null){
            houseDoorT.setUserName(MD5.encrypt(houseDoorT.getUserName()));
        }
        List<HouseDoorT> list = houseDoorTService.selectHouseDoorReturnList(houseDoorT);
        for(HouseDoorT houseDoorVO:list){
            houseDoorVO.setUserName(MD5.decrypt(houseDoorVO.getUserName()));
        }
        return getDataTable(list);
    }




    @Log(title = "资金返还", businessType = BusinessType.DELETE)
	@DeleteMapping("/{doorId}")
    public AjaxResult remove(@PathVariable Long doorId)
    {
        int costid2= houseReturnTService.insertHouseReturnTByDoorIds(doorId,getUsername());
        HouseCostT houseCostVO = new HouseCostT();
        houseCostVO.setCostId(Long.valueOf(costid2));
        return AjaxResult.success(houseCostVO);

    }

    @GetMapping(value = "getNote/{costId}")
    public AjaxResult getNote(@PathVariable("costId") Long costId)
    {
        HouseReturnT houseReturnVO = houseReturnTService.selectHouseReturnNote(costId);
        return AjaxResult.success(houseReturnVO);
    }


}
